package com.kurumi.autoprint.service.impl;


import org.springframework.stereotype.Service;

import com.kurumi.autoprint.pojo.InpatientInfo;
import com.kurumi.autoprint.pojo.PrintPatientInfo;
import com.kurumi.autoprint.pojo.ReportFile;
import com.kurumi.autoprint.service.WebService;
import com.kurumi.autoprint.util.JsonUtil;
import com.kurumi.autoprint.util.WebServiceUtil;
@Service
public class WebServiceImpl implements WebService{
	
	@SuppressWarnings("unchecked")
	@Override
	public InpatientInfo testService(String webServiceUrl,String method,String param) {
		Object object = null;
		try {
			object = WebServiceUtil.getInpatientRecordsByIdNo(webServiceUrl,method,param);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(object==null) {
			return null;
		}
		
		InpatientInfo inpatientInfo = JsonUtil.jsonToPojo(object.toString(), InpatientInfo.class);
		
		return inpatientInfo;
		
	}

	@Override
	public PrintPatientInfo getInpatientRecord(String getInpatientRecordServiceUrl, String getPrintPatientInfoMethod, String id) {
		Object object = null;
		try {
			object = WebServiceUtil.getInpatientRecordsByIdNo(getInpatientRecordServiceUrl,getPrintPatientInfoMethod,id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(object==null) {
			return null;
		}
		
		PrintPatientInfo printPatientInfo = JsonUtil.jsonToPojo(object.toString(), PrintPatientInfo.class);
		System.out.println(printPatientInfo);
		
		return printPatientInfo;
		
	}

	@Override
	public ReportFile getReportFile(String getInpatientRecordServiceUrl, String getPrintPatientInfoMethod,
			String pathstring) {
		Object object = null;
		try {
			object = WebServiceUtil.getInpatientRecordsByIdNo(getInpatientRecordServiceUrl,getPrintPatientInfoMethod,pathstring);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(object==null) {
			return null;
		}
		
		ReportFile reportFile = JsonUtil.jsonToPojo(object.toString(), ReportFile.class);
		
		return reportFile;
	}

}
